package com.zoroki.student_score_system.controller;
import com.zoroki.student_score_system.domain.Course;
import com.zoroki.student_score_system.service.CourseService;
import com.zoroki.student_score_system.utils.Msg;
import com.zoroki.student_score_system.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/course")
public class CourseController {
    @Autowired
    CourseService courseService;


    @GetMapping("/findAllCourses")
    public @ResponseBody Result<List<Course>> findAllCourses() {
        return new Result<List<Course>>(0,courseService.findAllCourses(), Msg.SUCCESS);
    }

    @GetMapping("/findCourseById")
    public @ResponseBody Result<Course> findCourseById(int id) {
        return new Result<Course>(0,courseService.findCourseById(id), Msg.SUCCESS);
    }

    @GetMapping("/getCourseByName")
    public @ResponseBody Result<Course> getCourseByName(String name) {
        return new Result<Course>(0,courseService.getCourseByName(name), Msg.SUCCESS);
    }


    @PostMapping("/addCollege")
    public @ResponseBody Result<Boolean> addCourse(@RequestBody Course course) {
        return new Result<Boolean>(0,courseService.addCourse(course), Msg.SUCCESS);
    }

    @PostMapping("/updateCourse")
    public @ResponseBody Result<Boolean> updateCourse(@RequestBody Course course) {
        return new Result<Boolean>(0,courseService.updateCourse(course), Msg.SUCCESS);
    }

    @PostMapping("/deleteCourse")
    public @ResponseBody Result<Boolean> deleteCollege(int id) {
        return new Result<Boolean>(0,courseService.deleteCourse(id), Msg.SUCCESS);
    }

}
